﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus
{
    public partial class partneriForma : Form
    {
        private string uslovSQLUpitaZaPretraguPartnera;
        private string IDPartnera;

        public partneriForma(string uslov)
        {
            InitializeComponent();
            this.uslovSQLUpitaZaPretraguPartnera = uslov;
        }

        Partneri partnerObjekat = null;
        partnerForma partnerFormaObjekat = null;

        private void partneriForma_Load(object sender, EventArgs e)
        {
            partnerObjekat = new Partneri();
            partnerObjekat.PopuniDataGridViewPartneri(dataGridViewPartneri, uslovSQLUpitaZaPretraguPartnera);
            IDPartnera = dataGridViewPartneri.SelectedRows[0].Cells[0].Value.ToString();
            label1.Text = IDPartnera;
        }

        private void dataGridViewPartneri_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            IDPartnera = dataGridViewPartneri.SelectedRows[0].Cells[0].Value.ToString();
            label1.Text = IDPartnera;
            kalkulacijaForma.idPartnera = Convert.ToInt32(IDPartnera);
            IzlazniRacun.izlazniRacunForma.idPartnera = Convert.ToInt32(IDPartnera);
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonBrisi_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Da li ste sigurni da želite da obrišete izabranog Partnera? \n" +
                "NAPOMENA: Brisanje partnera uzrokovaće i brisanje njegovih žiro računa i kontakata", "Obaveštenje", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                partnerObjekat = new Partneri();
                partnerObjekat.ObrisiPartneraPremaID(Convert.ToInt32(IDPartnera));
                partnerObjekat.PopuniDataGridViewPartneri(dataGridViewPartneri, uslovSQLUpitaZaPretraguPartnera);
            }
        }

        private void dataGridViewPartneri_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            partnerFormaObjekat = new partnerForma(dataGridViewPartneri.SelectedRows[0].Cells[0].Value.ToString());
            partnerFormaObjekat.ShowDialog();
            this.Cursor = Cursors.Default;
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            partnerFormaObjekat = new partnerForma("");
            partnerFormaObjekat.ShowDialog();
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            partnerFormaObjekat = new partnerForma(dataGridViewPartneri.SelectedRows[0].Cells[0].Value.ToString());
            partnerFormaObjekat.ShowDialog();
            this.Cursor = Cursors.Default;
        }

        
    }
}
